<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thylemeaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>登录</title>
    <link href="css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" type="text/css" href="./layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="css/form.css">
    <script src="js/jquery-3.4.1.js"></script>
    <script src="js/bootstrap.min.js"></script>

    <script type="text/javascript">


        //更新图片
        function changeImg() {
            $("#showCode")[0].src = "code/create?" + new Date().getTime();
        }

        $(function () {

            $("#dis3")[0].style.display = "none";

            $("#showCode").click(function () {
                changeImg();
            })

            $("#form1").submit(function () {
                var phone = $("#username").val();
                var password = $("#password").val();
                var checkCode = $("#securityCode").val();
                if(phone==""||password==""||checkCode==""){
                    alert("请填完账号密码以及验证码再登录。")
                    return false;
                }

                var sendInfo = {
                    phone: phone,
                    password: password,
                    checkCode: checkCode
                }

                $.ajax({
                    // 编写json格式，设置属性和值
                    url: "user/login",
                    contentType: "application/json;charset=UTF-8",
                    data: JSON.stringify(sendInfo),
                    dataType: "json",
                    type: "post",
                    success: function (data) {
                        if (data.result != 1) {
                            alert(data.msg);
                            changeImg();
                        }else{
                            if(document.referrer.toString().indexOf("8080/Smart/")!=-1&&document.referrer.toString().indexOf("success")==-1&&document.referrer.toString().indexOf("register.html")==-1){
                                window.location.href = document.referrer;
                            }else{
                                window.location.href = "index02.html";
                            }
                        }
                    }

                });
                return false;
            });
        });


    </script>
</head>
<body background="img/background.jpg">

<div th:replace="header::#nav(activeUrl='login.html')"></div>

<div class="container">
    <div class="row">
        <div>
            <ol class="breadcrumb">
                <li><a href="#">您的位置：</a></li>
                <li><a href="index02.html">首页</a></li>
                <li >登录</li>
            </ol>
        </div>
        <div class="col-xs-12">
            <div class="layui-anim layui-anim-up col-md-6 col-xs-12 jumbotron">
                <div class="container">
                    <h1>Hello, world!</h1>
                    <p>登陆，一起发现新大陆</p>
                </div>
                <img src="img/register.jpg">
            </div>
            <div id="tableDiv" class="layui-anim layui-anim-up col-md-6 col-xs-12">
                <div>
                    <table id="table">
                        <form action="#" method="post" id="form1">
                            <tr>
                                <td class="tdLeft"><i class="layui-icon layui-icon-username" style="color: #40AFFE"></i> <label for="username">用户名:</label></td>
                                <td class="tdRight"><input type="text" id="username" name="phone" placeholder="请输入用户名"/>
                                </td>
                            </tr>
                            <tr>
                                <td class="tdLeft"><i class="layui-icon layui-icon-password" style="color: #40AFFE">   </i> <label for="password">密码:</label></td>
                                <td class="tdRight"><input type="password" name="password" id="password"
                                                           placeholder="请输入"/></td>
                            </tr>
                            <tr>
                                <td class="tdLeft"><i class="layui-icon layui-icon-vercode"style="color: #40AFFE"></i> <label for="securityCode">验证码:</label></td>
                                <td class="tdRight">
                                    <input type="text" id="securityCode" name="securityCode" placeholder="请输入验证码"/>
                                    <img class="showCode" id="showCode" src="code/create"></img></td>
                            </tr>
                            <tr>
                                <td colspan="2" class="tdCenter">
                                    <input type="submit" id="btn_submit" value="登录">
<!--                                    <button type="button" class="layui-btn layui-btn-radius layui-btn-primary" id="btn_submit" >登录</button>-->
                                </td>
                            </tr>
                        </form>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="./layui/layui.all.js"></script>
</html>